package com.its.fialBack;

import com.its.client.UserServiceClient;
import com.its.pojo.User;
import com.its.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author 朱厚强
 * @version 1.0
 * @classname UserServiceFailBack
 * 请求失败的 feign 处理逻辑
 */
@Slf4j
@Component
public class UserServiceFailBack implements FallbackFactory<UserServiceClient> {
    /*return new UserServiceFeignClient() {
    //内部类实现的是错误的逻辑处理
    @Override
    public User queryById(Long id) {
        //log
        log.error("远程调用失败，服务已经降级或熔断处理！！");
        System.out.println("远程调用失败，服务已经降级或熔断处理！！");
        return new User();
    }
    };*/
    //内部类实现的是错误的逻辑处理
    @Override
    public UserServiceClient create(Throwable cause) {
        return id -> {
            //log
            log.error("远程调用失败，服务已经降级或熔断处理！！");
            System.out.println("远程调用失败，服务已经降级或熔断处理！！");
            User user = new User();
            return Result.ok().data(user);
        };
    }
}
